package com.jj.controller;

import com.jj.pojo.Emp;
import com.jj.pojo.Result;
import com.jj.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;
//    根据ID查询员工信息
    @GetMapping("/{id}")
    public Result select(@PathVariable Integer id){
        log.info("查询员工信息，id为：{}",id);
        List<Emp> empList = empService.select(id);
        return Result.success(empList);
    }
//    删除员工信息
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable Integer ids){
        log.info("删除员工信息，id为：{}", ids);
        empService.delete(ids);
        return Result.success();
    }
//    添加员工信息
    @PostMapping
    public Result insert(@RequestBody Emp emp){
        log.info("添加员工信息：{}", emp);
        empService.insert(emp);
        return Result.success();
    }
//    修改员工信息
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工信息：{}", emp);
        empService.update(emp);
        return Result.success();
    }
    //    查询员工所有信息
    @GetMapping
    public Result selete(Emp  emp){
        log.info("查询员工所有信息:{}",emp);
        List<Emp> empList1 = empService.select1(emp);
        return Result.success(empList1);
    }
}
